From 2c2d05fd0a2c3c26d765f8a6beb88d907a097c1d Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 11 Feb 2024 14:54:52 +0000 Subject: refactor: Migrating to trpc instead of next's route handers --- .../web/app/api/v1/bookmarks/[bookmarkId]/route.ts | 70 ---------------------- 1 file changed, 70 deletions(-) delete mode 100644 packages/web/app/api/v1/bookmarks/[bookmarkId]/route.ts (limited to 'packages/web/app/api/v1/bookmarks/[bookmarkId]') diff --git a/packages/web/app/api/v1/bookmarks/[bookmarkId]/route.ts b/packages/web/app/api/v1/bookmarks/[bookmarkId]/route.ts deleted file mode 100644 index 3e57fa65..00000000 --- a/packages/web/app/api/v1/bookmarks/[bookmarkId]/route.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { authOptions } from "@/lib/auth"; -import { deleteBookmark, updateBookmark } from "@/lib/services/bookmarks"; -import { - ZBookmark, - zUpdateBookmarksRequestSchema, -} from "@/lib/types/api/bookmarks"; -import { Prisma } from "@remember/db"; - -import { getServerSession } from "next-auth"; -import { NextRequest, NextResponse } from "next/server"; - -export async function PATCH( - request: NextRequest, - { params }: { params: { bookmarkId: string } }, -) { - const session = await getServerSession(authOptions); - if (!session) { - return new Response(null, { status: 401 }); - } - - const updateJson = await request.json(); - const update = zUpdateBookmarksRequestSchema.safeParse(updateJson); - if (!update.success) { - return new Response(null, { status: 400 }); - } - - try { - const bookmark: ZBookmark = await updateBookmark( - params.bookmarkId, - session.user.id, - update.data, - ); - return NextResponse.json(bookmark); - } catch (e: unknown) { - if ( - e instanceof Prisma.PrismaClientKnownRequestError && - e.code === "P2025" // RecordNotFound - ) { - return new Response(null, { status: 404 }); - } else { - throw e; - } - } -} - -export async function DELETE( - _request: NextRequest, - { params }: { params: { bookmarkId: string } }, -) { - // TODO: We probably should be using an API key here instead of the session; - const session = await getServerSession(authOptions); - if (!session) { - return new Response(null, { status: 401 }); - } - - try { - await deleteBookmark(params.bookmarkId, session.user.id); - } catch (e: unknown) { - if ( - e instanceof Prisma.PrismaClientKnownRequestError && - e.code === "P2025" // RecordNotFound - ) { - return new Response(null, { status: 404 }); - } else { - throw e; - } - } - - return new Response(null, { status: 204 }); -} -- cgit v1.2.3-70-g09d2